package com.oracle.threadpoolreject;

import java.util.concurrent.*;

/**
 * @author zhouyanxiang
 * @create 2020-08-2020/8/18-23:49
 */
public class AbortPolicyTest implements Runnable{

    public static void main(String[] args) {
        AbortPolicy abortPolicy = new AbortPolicy();
        TimeUnit unit;
        BlockingQueue workQueue = new LinkedBlockingQueue<>();
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(10, 20, 60, TimeUnit.SECONDS, workQueue);
        abortPolicy.rejectedExecution(new AbortPolicyTest(),threadPoolExecutor);
    }

    @Override
    public void run() {
        System.out.println(" run... ");
    }

    static class AbortPolicy implements RejectedExecutionHandler{
        @Override
        public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
            throw new RejectedExecutionException("Task"  + r.toString() + " rejected from " +  executor.toString());
        }
    }
    
}
